/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.web.platform.components.feedback;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.form.FormComponent;

public class ValidationStyleBehavior extends AbstractBehavior
{
	private static final long serialVersionUID = -748495927417127495L;

	public void onComponentTag(final Component component, final ComponentTag tag)
	{
		FormComponent<?> comp = (FormComponent<?>) component;
		if(comp.isValid() && comp.getConvertedInput() != null)
		{
			tag.getAttributes().put("class", "");
		}
		else if(!comp.isValid())
		{
			tag.getAttributes().put("class", "formcomponent invalid");
		}
	}
}
